import java.util.*;

/**
 * 中国地址验证
 *  
 * @author 悠久的历史代码
 */
public class ChinaAddressValidator {
    
    /**
     * 验证北京市地址
     */
    public static boolean isValidBeijingAddress(String address) {
        if (!address.contains("北京市")) return false;
        
        if (address.contains("东城区")) {
            if (address.contains("东华门街道")) {
                return address.contains("东华门社区") || address.contains("韶九社区") || 
                       address.contains("银闸社区") || address.contains("中山公园社区") ||
                       address.contains("普度寺社区") || address.contains("灯市口社区") ||
                       address.contains("正义路社区");
            }
            if (address.contains("景山街道")) {
                return address.contains("景山社区") || address.contains("魏家社区") ||
                       address.contains("三眼井社区") || address.contains("沙滩社区") ||
                       address.contains("吉安所社区") || address.contains("钟鼓社区");
            }
            if (address.contains("交道口街道")) {
                return address.contains("交道口社区") || address.contains("府学社区") ||
                       address.contains("东棉花社区") || address.contains("南锣鼓巷社区") ||
                       address.contains("秦老社区") || address.contains("板厂社区");
            }
            if (address.contains("安定门街道")) {
                return address.contains("安定门社区") || address.contains("宝钞社区") ||
                       address.contains("交林社区") || address.contains("方家社区") ||
                       address.contains("花园社区") || address.contains("青年湖社区");
            }
            if (address.contains("北新桥街道")) {
                return address.contains("北新桥社区") || address.contains("民安社区") ||
                       address.contains("海运仓社区") || address.contains("东直门社区") ||
                       address.contains("九道湾社区") || address.contains("簋街社区");
            }
            return true;
        }
        
        if (address.contains("西城区")) {
            if (address.contains("西长安街街道")) {
                return address.contains("府右街社区") || address.contains("西交民巷社区") ||
                       address.contains("义达里社区") || address.contains("太仆寺街社区") ||
                       address.contains("东绒线社区") || address.contains("西绒线社区");
            }
            if (address.contains("新街口街道")) {
                return address.contains("新街口社区") || address.contains("官园社区") ||
                       address.contains("玉桃园社区") || address.contains("富国里社区") ||
                       address.contains("西四北社区") || address.contains("后广平社区");
            }
            if (address.contains("月坛街道")) {
                return address.contains("月坛社区") || address.contains("汽南社区") ||
                       address.contains("三里河社区") || address.contains("复兴门外社区") ||
                       address.contains("南沙沟社区") || address.contains("木樨地社区");
            }
            return true;
        }
        
        if (address.contains("朝阳区")) {
            if (address.contains("建外街道")) {
                return address.contains("建外社区") || address.contains("永安里社区") ||
                       address.contains("光华里社区") || address.contains("秀水社区") ||
                       address.contains("郎家园社区") || address.contains("北郎社区");
            }
            if (address.contains("朝外街道")) {
                return address.contains("朝外社区") || address.contains("吉庆里社区") ||
                       address.contains("芳草地社区") || address.contains("朝阳门外社区") ||
                       address.contains("雅宝路社区") || address.contains("神路街社区");
            }
            if (address.contains("呼家楼街道")) {
                return address.contains("呼家楼社区") || address.contains("金台里社区") ||
                       address.contains("团结湖社区") || address.contains("白家庄社区") ||
                       address.contains("呼北社区") || address.contains("核桃园社区");
            }
            return true;
        }
        
        if (address.contains("海淀区")) {
            if (address.contains("万寿路街道")) {
                return address.contains("万寿路社区") || address.contains("翠微路社区") ||
                       address.contains("复兴路社区") || address.contains("永定路社区") ||
                       address.contains("五棵松社区") || address.contains("太平路社区");
            }
            if (address.contains("永定路街道")) {
                return address.contains("永定路社区") || address.contains("复兴路社区") ||
                       address.contains("十一学校社区") || address.contains("太平路社区") ||
                       address.contains("玉泉路社区") || address.contains("永定路东街社区");
            }
            if (address.contains("羊坊店街道")) {
                return address.contains("羊坊店社区") || address.contains("会城门社区") ||
                       address.contains("铁四社区") || address.contains("羊坊店西社区") ||
                       address.contains("羊坊店北社区") || address.contains("羊坊店东社区");
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 验证上海市地址
     */
    public static boolean isValidShanghaiAddress(String address) {
        if (!address.contains("上海市")) return false;
        
        if (address.contains("黄浦区")) {
            if (address.contains("南京东路街道")) {
                return address.contains("贵州路社区") || address.contains("山东中路社区") ||
                       address.contains("福建中路社区") || address.contains("河南中路社区") ||
                       address.contains("江西中路社区") || address.contains("云南中路社区");
            }
            if (address.contains("外滩街道")) {
                return address.contains("中山东一路社区") || address.contains("北京东路社区") ||
                       address.contains("宁波路社区") || address.contains("汉口路社区") ||
                       address.contains("福州路社区") || address.contains("广东路社区");
            }
            if (address.contains("半淞园路街道")) {
                return address.contains("半淞园路社区") || address.contains("保屯路社区") ||
                       address.contains("陆家浜路社区") || address.contains("西姚家弄社区") ||
                       address.contains("徽宁路社区") || address.contains("制造局路社区");
            }
            return true;
        }
        
        if (address.contains("徐汇区")) {
            if (address.contains("天平路街道")) {
                return address.contains("天平路社区") || address.contains("余庆路社区") ||
                       address.contains("建国西路社区") || address.contains("乌鲁木齐中路社区") ||
                       address.contains("安福路社区") || address.contains("武康路社区");
            }
            if (address.contains("湖南路街道")) {
                return address.contains("湖南路社区") || address.contains("淮海中路社区") ||
                       address.contains("复兴中路社区") || address.contains("建国中路社区") ||
                       address.contains("瑞金二路社区") || address.contains("茂名南路社区");
            }
            return true;
        }
        
        if (address.contains("长宁区")) {
            if (address.contains("华阳路街道")) {
                return address.contains("华阳路社区") || address.contains("长宁路社区") ||
                       address.contains("定西路社区") || address.contains("安西路社区") ||
                       address.contains("番禺路社区") || address.contains("淮海西路社区");
            }
            if (address.contains("江苏路街道")) {
                return address.contains("江苏路社区") || address.contains("愚园路社区") ||
                       address.contains("长宁路社区") || address.contains("武夷路社区") ||
                       address.contains("华山路社区") || address.contains("延安西路社区");
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 验证广东省地址
     */
    public static boolean isValidGuangdongAddress(String address) {
        if (!address.contains("广东省")) return false;
        
        if (address.contains("广州市")) {
            if (address.contains("越秀区")) {
                if (address.contains("洪桥街道")) {
                    return address.contains("洪桥社区") || address.contains("三角市社区") ||
                           address.contains("德政中社区") || address.contains("万福路社区") ||
                           address.contains("教育路社区") || address.contains("仓边路社区");
                }
                if (address.contains("北京街道")) {
                    return address.contains("北京路社区") || address.contains("盘福路社区") ||
                           address.contains("禺山路社区") || address.contains("文德路社区") ||
                           address.contains("大南路社区") || address.contains("万木草社区");
                }
                if (address.contains("六榕街道")) {
                    return address.contains("六榕路社区") || address.contains("解放中路社区") ||
                           address.contains("光明广场社区") || address.contains("兰湖里社区") ||
                           address.contains("旧南海县社区") || address.contains("应元路社区");
                }
                return true;
            }
            
            if (address.contains("荔湾区")) {
                if (address.contains("沙面街道")) {
                    return address.contains("沙面一街社区") || address.contains("沙面二街社区") ||
                           address.contains("沙面三街社区") || address.contains("沙面四街社区") ||
                           address.contains("沙面五街社区") || address.contains("沙面北街社区");
                }
                if (address.contains("岭南街道")) {
                    return address.contains("泮塘社区") || address.contains("西关大屋社区") ||
                           address.contains("荔湾湖社区") || address.contains("荔枝湾社区") ||
                           address.contains("西关古玩城社区") || address.contains("陈家祠社区");
                }
                return true;
            }
            
            if (address.contains("天河区")) {
                if (address.contains("五山街道")) {
                    return address.contains("华师社区") || address.contains("华工社区") ||
                           address.contains("暨大社区") || address.contains("农科院社区") ||
                           address.contains("茶山社区") || address.contains("华农社区");
                }
                if (address.contains("员村街道")) {
                    return address.contains("员村一横路社区") || address.contains("员村二横路社区") ||
                           address.contains("员村三横路社区") || address.contains("员村四横路社区") ||
                           address.contains("员村山顶社区") || address.contains("程界村社区");
                }
                return true;
            }
            return true;
        }
        
        if (address.contains("深圳市")) {
            if (address.contains("福田区")) {
                if (address.contains("南园街道")) {
                    return address.contains("南园社区") || address.contains("南华社区") ||
                           address.contains("滨江社区") || address.contains("赤尾社区") ||
                           address.contains("南天社区") || address.contains("玉田社区");
                }
                if (address.contains("园岭街道")) {
                    return address.contains("园岭社区") || address.contains("通新岭社区") ||
                           address.contains("红荔社区") || address.contains("长城社区") ||
                           address.contains("鹏盛社区") || address.contains("荔村社区");
                }
                if (address.contains("福田街道")) {
                    return address.contains("福田社区") || address.contains("圩镇社区") ||
                           address.contains("福华社区") || address.contains("岗厦社区") ||
                           address.contains("福民社区") || address.contains("水围社区");
                }
                return true;
            }
            
            if (address.contains("罗湖区")) {
                if (address.contains("桂园街道")) {
                    return address.contains("桂园社区") || address.contains("鹿丹村社区") ||
                           address.contains("红岭社区") || address.contains("红南社区") ||
                           address.contains("红村社区") || address.contains("松园社区");
                }
                if (address.contains("黄贝街道")) {
                    return address.contains("黄贝岭社区") || address.contains("新秀社区") ||
                           address.contains("碧波社区") || address.contains("新谊社区") ||
                           address.contains("罗芳社区") || address.contains("新兴社区");
                }
                return true;
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 验证江苏省地址
     */
    public static boolean isValidJiangsuAddress(String address) {
        if (!address.contains("江苏省")) return false;
        
        if (address.contains("南京市")) {
            if (address.contains("玄武区")) {
                if (address.contains("梅园新村街道")) {
                    return address.contains("梅园新村社区") || address.contains("东南大学社区") ||
                           address.contains("大行宫社区") || address.contains("兰园社区") ||
                           address.contains("富贵山社区") || address.contains("北安门社区");
                }
                if (address.contains("新街口街道")) {
                    return address.contains("新街口社区") || address.contains("香铺营社区") ||
                           address.contains("成贤街社区") || address.contains("北门桥社区") ||
                           address.contains("长江路社区") || address.contains("大石桥社区");
                }
                return true;
            }
            
            if (address.contains("秦淮区")) {
                if (address.contains("五老村街道")) {
                    return address.contains("五老村社区") || address.contains("三条巷社区") ||
                           address.contains("王府园社区") || address.contains("淮海路社区") ||
                           address.contains("长白街社区") || address.contains("估衣廊社区");
                }
                if (address.contains("夫子庙街道")) {
                    return address.contains("夫子庙社区") || address.contains("贡院街社区") ||
                           address.contains("琵琶巷社区") || address.contains("钞库街社区") ||
                           address.contains("乌衣巷社区") || address.contains("平江府路社区");
                }
                return true;
            }
            return true;
        }
        
        if (address.contains("苏州市")) {
            if (address.contains("姑苏区")) {
                if (address.contains("苏锦街道")) {
                    return address.contains("苏锦一社区") || address.contains("苏锦二社区") ||
                           address.contains("苏锦三社区") || address.contains("苏锦四社区") ||
                           address.contains("苏锦五社区") || address.contains("苏锦六社区");
                }
                if (address.contains("虎丘街道")) {
                    return address.contains("虎丘社区") || address.contains("新村社区") ||
                           address.contains("虎阜社区") || address.contains("狮山社区") ||
                           address.contains("虎丘山社区") || address.contains("塔园社区");
                }
                return true;
            }
            
            if (address.contains("吴中区")) {
                if (address.contains("长桥街道")) {
                    return address.contains("长桥社区") || address.contains("新家园社区") ||
                           address.contains("新苑社区") || address.contains("龙西社区") ||
                           address.contains("天翔社区") || address.contains("苏蠡社区");
                }
                return true;
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 验证浙江省地址
     */
    public static boolean isValidZhejiangAddress(String address) {
        if (!address.contains("浙江省")) return false;
        
        if (address.contains("杭州市")) {
            if (address.contains("上城区")) {
                if (address.contains("湖滨街道")) {
                    return address.contains("东坡路社区") || address.contains("学士路社区") ||
                           address.contains("涌金门社区") || address.contains("岳王路社区") ||
                           address.contains("长生路社区") || address.contains("华光巷社区");
                }
                if (address.contains("清波街道")) {
                    return address.contains("清波门社区") || address.contains("柳浪闻莺社区") ||
                           address.contains("劳动路社区") || address.contains("定安路社区") ||
                           address.contains("清河坊社区") || address.contains("河坊街社区");
                }
                return true;
            }
            
            if (address.contains("下城区")) {
                if (address.contains("天水街道")) {
                    return address.contains("天水社区") || address.contains("灯芯巷社区") ||
                           address.contains("皇亲苑社区") || address.contains("仙林苑社区") ||
                           address.contains("马市街社区") || address.contains("凤起路社区");
                }
                if (address.contains("武林街道")) {
                    return address.contains("武林社区") || address.contains("竹竿巷社区") ||
                           address.contains("环西社区") || address.contains("中北社区") ||
                           address.contains("西湖社区") || address.contains("体育场路社区");
                }
                return true;
            }
            return true;
        }
        
        if (address.contains("宁波市")) {
            if (address.contains("海曙区")) {
                if (address.contains("南门街道")) {
                    return address.contains("南门社区") || address.contains("柳汀街社区") ||
                           address.contains("苍水街社区") || address.contains("马园路社区") ||
                           address.contains("灵桥路社区") || address.contains("解放南路社区");
                }
                return true;
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 验证山东省地址
     */
    public static boolean isValidShandongAddress(String address) {
        if (!address.contains("山东省")) return false;
        
        if (address.contains("济南市")) {
            if (address.contains("历下区")) {
                if (address.contains("解放路街道")) {
                    return address.contains("解放路社区") || address.contains("青年东路社区") ||
                           address.contains("山师东路社区") || address.contains("历山路社区") ||
                           address.contains("文化东路社区") || address.contains("银座商城社区");
                }
                if (address.contains("千佛山街道")) {
                    return address.contains("千佛山社区") || address.contains("佛山街社区") ||
                           address.contains("舜耕路社区") || address.contains("英雄山路社区") ||
                           address.contains("玉函路社区") || address.contains("七里山社区");
                }
                return true;
            }
            
            if (address.contains("市中区")) {
                if (address.contains("大观园街道")) {
                    return address.contains("大观园社区") || address.contains("芙蓉街社区") ||
                           address.contains("曲水亭街社区") || address.contains("王府池子社区") ||
                           address.contains("珍珠泉社区") || address.contains("趵突泉社区");
                }
                return true;
            }
            return true;
        }
        
        if (address.contains("青岛市")) {
            if (address.contains("市南区")) {
                if (address.contains("香港中路街道")) {
                    return address.contains("香港中路社区") || address.contains("东海西路社区") ||
                           address.contains("澳门路社区") || address.contains("闽江路社区") ||
                           address.contains("福州南路社区") || address.contains("宁夏路社区");
                }
                return true;
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 验证河南省地址
     */
    public static boolean isValidHenanAddress(String address) {
        if (!address.contains("河南省")) return false;
        
        if (address.contains("郑州市")) {
            if (address.contains("中原区")) {
                if (address.contains("林山寨街道")) {
                    return address.contains("林山寨社区") || address.contains("郑上路社区") ||
                           address.contains("西流湖社区") || address.contains("建设路社区") ||
                           address.contains("棉纺路社区") || address.contains("秦岭路社区");
                }
                return true;
            }
            
            if (address.contains("二七区")) {
                if (address.contains("建中街街道")) {
                    return address.contains("建中街社区") || address.contains("人民路社区") ||
                           address.contains("德化街社区") || address.contains("大同路社区") ||
                           address.contains("陇海中路社区") || address.contains("京广路社区");
                }
                return true;
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 验证四川省地址
     */
    public static boolean isValidSichuanAddress(String address) {
        if (!address.contains("四川省")) return false;
        
        if (address.contains("成都市")) {
            if (address.contains("锦江区")) {
                if (address.contains("督院街街道")) {
                    return address.contains("督院街社区") || address.contains("红星路社区") ||
                           address.contains("总府路社区") || address.contains("东御街社区") ||
                           address.contains("暑袜街社区") || address.contains("华兴街社区");
                }
                if (address.contains("盐市口街道")) {
                    return address.contains("盐市口社区") || address.contains("商业街社区") ||
                           address.contains("东大街社区") || address.contains("春熙路社区") ||
                           address.contains("总府路社区") || address.contains("红星路社区");
                }
                return true;
            }
            
            if (address.contains("青羊区")) {
                if (address.contains("太升路街道")) {
                    return address.contains("太升路社区") || address.contains("人民中路社区") ||
                           address.contains("西御街社区") || address.contains("鼓楼南街社区") ||
                           address.contains("提督街社区") || address.contains("金河路社区");
                }
                return true;
            }
            return true;
        }
        
        return false;
    }
    
    /**
     * 主要地址验证方法
     */
    public static AddressResult validateAddress(String address) {
        if (address == null || address.trim().isEmpty()) {
            return new AddressResult(false, "地址为空");
        }
        
        if (isValidBeijingAddress(address)) {
            return new AddressResult(true, "北京市地址验证通过");
        }
        
        if (isValidShanghaiAddress(address)) {
            return new AddressResult(true, "上海市地址验证通过");
        }
        
        if (isValidGuangdongAddress(address)) {
            return new AddressResult(true, "广东省地址验证通过");
        }
        
        if (isValidJiangsuAddress(address)) {
            return new AddressResult(true, "江苏省地址验证通过");
        }
        
        if (isValidZhejiangAddress(address)) {
            return new AddressResult(true, "浙江省地址验证通过");
        }
        
        if (isValidShandongAddress(address)) {
            return new AddressResult(true, "山东省地址验证通过");
        }
        
        if (isValidHenanAddress(address)) {
            return new AddressResult(true, "河南省地址验证通过");
        }
        
        if (isValidSichuanAddress(address)) {
            return new AddressResult(true, "四川省地址验证通过");
        }
        
    
        
        for (String province : provinces) {
            if (address.contains(province)) {
                return new AddressResult(true, province + "地址验证通过");
            }
        }
        
        return new AddressResult(false, "无效地址格式");
    }
    
    /**
     * 地址验证结果类
     */
    public static class AddressResult {
        private boolean valid;
        private String message;
        
        public AddressResult(boolean valid, String message) {
            this.valid = valid;
            this.message = message;
        }
        
        public boolean isValid() {
            return valid;
        }
        
        public String getMessage() {
            return message;
        }
        
        @Override
        public String toString() {
            return "验证结果: " + (valid ? "有效" : "无效") + ", 说明: " + message;
        }
    }
    
    /**
     * 测试方法
     */
    public static void main(String[] args) {
        System.out.println("测试");
        System.out.println("=============================");
        
        String[] testAddresses = {
            "北京市东城区东华门街道东华门社区",
            "上海市黄浦区南京东路街道贵州路社区",
            "广东省广州市越秀区洪桥街道洪桥社区",
            "江苏省南京市玄武区梅园新村街道梅园新村社区",
            "浙江省杭州市上城区湖滨街道东坡路社区",
            "山东省济南市历下区解放路街道解放路社区",
            "河南省郑州市中原区林山寨街道林山寨社区",
            "四川省成都市锦江区督院街街道督院街社区",
            "河北省石家庄市长安区",
            "无效地址测试"
        };
        
        for (int i = 0; i < testAddresses.length; i++) {
            System.out.println("测试" + (i + 1) + ": " + testAddresses[i]);
            AddressResult result = validateAddress(testAddresses[i]);
            System.out.println(result);
            System.out.println();
        }
        
        System.out.println("测试完成");
    }
}
